const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentId: '1',
    section: [{
      name: '今日',
      typeId: '1'
    }, {
      name: '昨日',
      typeId: '2'
    }],
    team_id: '', // 小组id
    team_name: '', // 小组名称
    today: '', // 今日
    yesterday: '', // 昨日
    tomorrow: '', // 明天
    todayList: [], // 今日列表
    yesterdayList: [], // 昨日列表
    fontSetSize: 'small', // 用户设置的字体大小（'small'：小，'middle'：中，'large'：大）
  },
  handleTap: function(e) {
    let id = e.currentTarget.id;
    if(id){
      this.setData({
        currentId:id
      })
    }
  },

  /**
   * 今日
   */
  getToday () {
    let token = wx.getStorageSync('token')
    app.http({
      config: {
        url: '/api/User/team_user_work',
        data: {
          token,
          team_id: this.data.team_id,
          start_time: this.data.today,
          end_time: this.data.tomorrow
        },
        method: 'POST'
      },
      isAuth: true
    }).then(res => {
      console.log(res, 'todayRes')
      this.setData({
        todayList: res.data.data
      })
    }).catch(err => {
      console.log(err, 'todayErr')
    })
  },

  /**
   * 昨日
   */
  getYesterday () {
    let token = wx.getStorageSync('token')
    app.http({
      config: {
        url: '/api/User/team_user_work',
        data: {
          token,
          team_id: this.data.team_id,
          start_time: this.data.yesterday,
          end_time: this.data.today
        },
        method: 'POST'
      },
      isAuth: true
    }).then(res => {
      console.log(res, 'yesterdayRes')
      this.setData({
        yesterdayList: res.data.data
      })
    }).catch(err => {
      console.log(err, 'yesterdayErr')
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let team_id = options.team_id
    let team_name = options.team_name
    app.setTitle(team_name)
    this.setData({
      team_id,
      team_name
    })
    let time = new Date()
    let year = time.getFullYear()
    let month = time.getMonth()
    let date = time.getDate()
    let oneDayLast = date - 1
    let oneDayNext = date + 1
    month = month.length > 1 ? month : ('0' + month)
    date = date.length > 1 ? date : ('0' + date)
    oneDayLast = oneDayLast.length > 1 ? oneDayLast : ('0' + oneDayLast)
    oneDayNext = oneDayNext.length > 1 ? oneDayNext : ('0' + oneDayNext)
    this.setData({
      today: `${year}-${month}-${date}`,
      yesterday: `${year}-${month}-${oneDayLast}`,
      tomorrow: `${year}-${month}-${oneDayNext}`
    })
    console.log('team_id', team_id)
    // console.log(this.data.today, this.data.yesterday)
    this.getToday()
    this.getYesterday()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let fontSetSize = wx.getStorageSync('fontSetSize') // 本地缓存中用户设置的字体大小
    if (fontSetSize) {
      this.setData({
        fontSetSize
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})